package com.hezuti.common.dao;

import java.util.Collections;
import java.util.Map;
import java.util.Set;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.InitializingBean;

/**
 * 
 * @author xiaoyu.dou
 *
 */
public class RoutingSessionFactory implements InitializingBean {

	private Map<Object, SessionFactory> sessionFactories;
	/**
	 * 
	 */
	public void afterPropertiesSet() throws Exception {
		if (this.getSessionFactories() == null) {
			throw new IllegalArgumentException("sessionFactories is required");
		}
	}
	/**
	 * 
	 * @param sessionFactories
	 */
	public void setSessionFactories(Map<Object, SessionFactory> sessionFactories) {
		this.sessionFactories = sessionFactories;
	}
	/**
	 * 
	 * @return
	 */
	public Map<Object, SessionFactory> getSessionFactories() {
		return sessionFactories;
	}
	/**
	 * 
	 * @param key
	 * @return
	 */
	public SessionFactory getSessionFactory(String key) {
		return sessionFactories.get(key);
	}

	/**
	 * 获得RoutingSessionFactory的所有key
	 * 
	 * @return
	 */
	public Set<Object> getLookupKeys() {
		return Collections.unmodifiableSet(sessionFactories.keySet());
	}
}
